package es.deusto.ingenieria.sd.sms.client.remote;

import es.deusto.ingenieria.sd.sms.server.remote.IPlayManager;

public class RMIServiceLocator{
	/** 
	 * The Cache - Limitation: one server at a time
	 * Proposed improvement: list of services
	 */
	private IPlayManager service;

    /** Creates a new instance of RMIServiceLocator */
    public RMIServiceLocator(){ 
    
    }

    public void setService(String ip, String port, String serviceName) {    
    	// Add your code to get the TARGET reference HERE  
    	if (System.getSecurityManager() == null) {
    		 System.setSecurityManager(new SecurityManager());
    		 }
    		 
    		 try {
    		 String name = "//" + ip + ":" + port + "/" + serviceName;
    		 //service = (ITVProgramManager) java.rmi.Naming.lookup(name);
    		 } catch (Exception e) {
    		 System.err.println("- Exception running the client: " + e.getMessage());
    		 //e.printStackTrace();
    		 }
    	
    }
    
    public IPlayManager getService() {    	
    	// Add your code to return the TARGET reference HERE
    	return service;
    }
}